/*Mootools Script: Assets.js Authors: Valerio Proietti*/
Asset.javascript = function(source, properties){
properties = $extend({
onload: $empty,
document: document,
check: $lambda(true)
}, properties);

var script = new Element('script', {src: source, type: 'text/javascript'});

var load = properties.onload.bind(script), check = properties.check, doc = properties.document;
delete properties.onload; delete properties.check; delete properties.document;

var aktiveScript=null;
//überprüft ob Script schon geladen by Benedikt Morschheuse 2009:
$(doc.head).getElements('script').each(function(script_element){
if(script_element.getProperty('src')==source){
aktiveScript=script_element;
}
});
if(aktiveScript!=null){
script.fireEvent('jsLoaded');
return aktiveScript;//abbruch -> Script schon da
}else{
script.addEvents({
load: load,
readystatechange: function(){
if (['loaded', 'complete'].contains(this.readyState)){
load();
script.fireEvent('jsLoaded');
/*by Benedikt Morschheuse 2009: Abfangen z.B. mit:
var moreAccordionScript = new Asset.javascript('js/moreScripts/accordion.js', {
'events': {
'jsLoaded': function (jsObj){
alert('hallo'+jsObj);
}.bindWithEvent(this)
}
});//ergänzt JS*/
}
}
}).set(properties);
if (Browser.Engine.webkit419) var checker = (function(){
if (!$try(check)) return;
$clear(checker);
load();
script.fireEvent('jsLoaded');
}).periodical(50);
return script.inject(doc.head);
}
};
